<script setup>
// import { GetSalesCollectionListAPI } from '@/api/statistics/procure/orderTack.js'
const { proxy } = getCurrentInstance()

const { statistics_procure_order_track_state } = proxy.useDict('statistics_procure_order_track_state')

// 列表数据
const tableData = ref([])

// 按钮
const buttonList = ref([{ type: 'export', hasPermi: 'finance:dataChange:export' }])

// 列表枚举
const column = ref([
  { label: '客户编码', prop: 'customerCode', width: '120' },
  { label: '客户名称', prop: 'customerName' },
  { label: '客户类别', prop: 'customerCategory' },
  { label: '销售人员', prop: 'saleBy', width: '150' },
  { label: '单据号', prop: 'receiptNo' },
  { label: '单据类型', prop: 'documentType' },
  { label: '开单日期', prop: 'drawerTime' },
  { label: '销售金额', prop: 'saleAmont' },
  { label: '已收款', prop: 'amountPaid' },
  { label: '整单折扣', prop: 'documentDiscount' },
  { label: '未收款', prop: 'outstandingPayment' },
  { label: '收款率', prop: 'ratePayment' },
  { label: '备注', prop: 'remark' }
])

// 状态
const state = reactive({
  treeLoading: false,
  loading: false, // 列表加载状态
  btnLoading: false, // 按钮加载状态
  isShow: false, // 弹窗状态
  title: '新增', // 弹窗标题
  total: 0 // 列表总量
})

// 查询条件
const query = reactive({
  pageNum: 1,
  pageSize: 10
})

// 查询条件 枚举
const selectList = ref([
  { label: '开单日期', type: '日期范围' },
  { label: '客户', model: 'customerName', type: '输入框' },
  { label: '销售人员', model: 'saleBy', type: '输入框' }
])

// 导出
const exportFun = () => {}

// 查询条件
const selectSubmit = val => {
  Object.keys(val).forEach(keyItem => (query[keyItem] = val[keyItem]))
  getList()
}

// 获取列表
const getList = async () => {
  state.loading = true
  try {
    const result = await GetSalesCollectionListAPI(query)
    tableData.value = result.rows
    state.total = result.total
  } catch {
  } finally {
    state.loading = false
  }
}
getList()
</script>

<template>
  <div class="app-container">
    <!-- 查询条件组件 -->
    <p-select-form :selectForm="selectList" @selectSubmit="selectSubmit" />
    <el-card>
      <!-- 按钮组件 -->
      <p-button :list="buttonList" @add="addDic" />
      <!-- 表格数据 -->
      <p-table
        summary
        class="tableClass"
        :isSel="false"
        :loading="state.loading"
        :data="tableData"
        :column="column"
        :amountList="['saleAmont', 'amountPaid', 'documentDiscount', 'outstandingPayment']"
        v-model:page="query.pageNum"
        v-model:limit="query.pageSize"
        :total="state.total"
        @change="handleSelectionChange"
        @pagination="getList"
      >
        <template #columnCell="{ column, record }">
          <p-dictTag
            v-if="column.label == '单据状态'"
            :options="statistics_procure_order_track_state"
            :value="record.status"
          />
          <!-- 辅助属性 -->
          <p-producer :data="record.auxiliaryAttribute" v-if="column.label == '辅助属性'" />
          <div v-if="column.label == '收款率'">{{ record.ratePayment }}%</div>
        </template>
      </p-table>
    </el-card>
  </div>
</template>
<style scoped lang="scss"></style>
